/*
 * @Author: WuFeng <763467339@qq.com>
 * @Date: 2022-10-09 18:41:43
 * @LastEditTime: 2022-10-10 11:24:55
 * @LastEditors: WuFeng <763467339@qq.com>
 * @Description: 
 * @FilePath: \vue-code-design\main.js
 * @Copyright 版权声明
 */
const express = require("express")

const app = express()
const port = 9999 // 设置端口号，如果端口号被占用需要自己修改，否则无法跑起来(建议不要用80和8080，一般情况都会被占用)

app.listen(port, () => {
  // 打印接口用例地址
  console.log(`http://127.0.0.1:${port}/codeDesign/getTables - 获取所有表信息`)
  console.log(`http://127.0.0.1:${port}/codeDesign/getTableInfo - 获取某张表信息`)
  console.log(`http://127.0.0.1:${port}/codeDesign/genderCode - 自动生成单表代码接口`)
  console.log(`http://127.0.0.1:${port}/codeDesign/genderCodeCustom - 自定义生成单表代码接口`)
})

app.use(require("body-parser").json())
app.use(require("body-parser").urlencoded({ extended: false }))

// 设置跨域访问
app.all("*", function (req, res, next) {
  res.header("Access-Control-Allow-Origin", "*")
  res.header("Access-Control-Allow-Headers", "*")
  res.header("Access-Control-Allow-Methods", "*")
  // res.header("X-Powered-By", "http://www.shuzhiqiang.com")
  res.header("Content-Type", "application/json;charset=utf-8")
  res.header("Access-Control-Allow-Credentials", true) // 携带cookie跨域请求
  req.method.toUpperCase() === "OPTIONS" ? res.sendStatus(200) : next() // 防止在预请求阶段就响应接口
})

// 加入前端需要访问的接口API名称↓↓↓↓
app.use("/codeDesign", require("./api/codeDesign"))